﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Byteabyte
{
    class IcsFile
    {
        public List<IcsEvent> Events { get; set; }

        /// <summary>
        /// Lee el archivo ICS dado y carga los eventos encontrados
        /// </summary>
        /// <param name="fileName"></param>
        public void Parse(string fileName)
        {
            StreamReader reader = null;
            try
            {
                reader = new StreamReader(fileName);
                String icsLine;
                while ((icsLine = reader.ReadLine()) != null)
                {
                    if(icsLine.ToUpper().Equals(IcsStrings.IcsEventStart))
                    {
                        var icsEvent = CreateEvent();
                        icsEvent.ParseEvent(reader);
                    }
                }
            }
            finally
            {
                if(reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }

        private IcsEvent CreateEvent()
        {
            if(Events == null) Events = new List<IcsEvent>();
            var ev = new IcsEvent();
            Events.Add(ev);
            return ev;
        }
    }
}
